/**
 * 
 */
package com.postek.coyote.postekwifi;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;
import com.postek.coyote.postekwifi.bean.LabelBean;
import com.postek.coyote.postekwifi.bean.TBean;

import java.util.ArrayList;

public class PrintTActivity extends AppCompatActivity implements OnClickListener {

	private CDFPTKAndroid cdf = MainActivity.cdf;
	private ArrayList<LabelBean> labelBeans = MainActivity.labelBeans;

	private Button btnPrintT = null;
	private Button btnCancel = null;

	private EditText et_T1 = null;
	private EditText et_T2 = null;
	private Spinner sp_T3 = null;
	private Spinner sp_T4 = null;
	private EditText et_T5 = null;
	private EditText et_T6 = null;
	private Spinner sp_T7 = null;
	private EditText et_TS = null;
	private EditText et_print_number=null;
	private EditText et_print_cpnumber=null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.print_t);

		et_T1 = (EditText) findViewById(R.id.et_print_T1);
		et_T2 = (EditText) findViewById(R.id.et_print_T2);
		sp_T3 = (Spinner) findViewById(R.id.sp_print_T3);
		sp_T4 = (Spinner) findViewById(R.id.sp_print_T4);
		et_T5 = (EditText) findViewById(R.id.et_print_T5);
		et_T6 = (EditText) findViewById(R.id.et_print_T6);
		sp_T7 = (Spinner) findViewById(R.id.sp_print_T7);
		et_TS = (EditText) findViewById(R.id.et_print_TS);
		et_print_number= (EditText) findViewById(R.id.et_print_number);
		et_print_cpnumber= (EditText) findViewById(R.id.et_print_cpnumber);

		btnPrintT = (Button) findViewById(R.id.btn_printT_print);
		btnCancel = (Button) findViewById(R.id.btn_printT_cancel);

		btnCancel.setOnClickListener(this);

		btnPrintT.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iT1 = 0;
				int iT2 = 0;
				int iT3 = sp_T3.getSelectedItemPosition();
				char iT4 = (((sp_T4.getSelectedItemPosition() + 1) + "")
						.toCharArray())[0];
				int iT5 = 0;
				int iT6 = 0;
				char iT7 = (((String) sp_T7.getSelectedItem()).toCharArray())[0];
				int number=Integer.parseInt(et_print_number.getText().toString());
				int cpnumber=Integer.parseInt(et_print_cpnumber.getText().toString());
				String iTS = "";

				if (!("".equals(et_T1.getText().toString()))) {
					iT1 = Integer.parseInt(et_T1.getText().toString());
				}
				if (!("".equals(et_T2.getText().toString()))) {
					iT2 = Integer.parseInt(et_T2.getText().toString());
				}
				if (!("".equals(et_T5.getText().toString()))) {
					iT5 = Integer.parseInt(et_T5.getText().toString());
				}
				if (!("".equals(et_T6.getText().toString()))) {
					iT6 = Integer.parseInt(et_T6.getText().toString());
				}
				iTS = et_TS.getText().toString();

				int nReturn = cdf.PTK_DrawText(iT1, iT2, iT3, iT4, iT5, iT6,
						iT7, iTS);

				if (nReturn == 0) {
					TBean tBean = new TBean(iT1, iT2, iT3, iT4, iT5, iT6,
							iT7, iTS);
					labelBeans.add(tBean);
					Toast.makeText(PrintTActivity.this,  R.string.setting_success,
							Toast.LENGTH_SHORT).show();
					cdf.PTK_PrintLabel(number, cpnumber);
				} else {
					Toast.makeText(PrintTActivity.this,  R.string.setting_fail,
							Toast.LENGTH_SHORT).show();
				}
			}
		});

	}

	@Override
	public void onClick(View v) {
	finish();
	}
}
